package com.wdb.common.configurer.authority;

import io.jsonwebtoken.Jwt;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnClass(Jwt.class)
@EnableConfigurationProperties(AuthorityProperties.class)
public class AuthorityConfigurer {
    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Bean
    public AuthorityExecutor authorityExecutor(AuthorityProperties properties) {
        if (logger.isDebugEnabled()) {
            logger.info("{}", "added authority executor");
        }

        return new AuthorityExecutor(properties.getSecret());
    }
}
